//
//  HSYPlayerBrightnessView.m
//  高仿暴走斗图
//
//  Created by key on 16/8/19.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "HSYPlayerBrightnessView.h"
#import "HSYBaseVideoPlayerView.h"

#define KVO_TO_SYSTEM_BRIGHTNESS        @"brightness"

@implementation HSYPlayerBrightnessView

- (instancetype)initWithLogo:(UIImage *)logo highLogo:(UIImage *)highLogo
{
    if (self = [super initWithLogo:logo highLogo:highLogo indicatorType:kHSYPlayerIndicatorProgessTypeBrightness]) {
        
    }
    return self;
}

- (void)toPreventOverlap
{
    //防止重叠
    HSYBaseVideoPlayerView *playerView = (HSYBaseVideoPlayerView *)self.superview;
    playerView.timeIndicatorView.hidden = YES;
    playerView.volumeIndicatorView.hidden = YES;
}

- (void)configScreenObserver
{
    [[UIScreen mainScreen] addObserver:self
                            forKeyPath:KVO_TO_SYSTEM_BRIGHTNESS
                               options:NSKeyValueObservingOptionNew
                               context:NULL];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
    if ([keyPath isEqualToString:KVO_TO_SYSTEM_BRIGHTNESS]) {
        CGFloat brightness = [change[@"new"] floatValue];
        [self updateIndicator:brightness];
    }
}

@end
